home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 May / PersonalComputerWorld-May2008-CoverdiscCD.iso / Software / Full / Nero 7 / Installation / Cab / C43E35C1.cab / gadgetA39847C5.js next >
Encoding:
JavaScript  |  2006-11-08  |  49.2 KB  |  1,480 lines

  1.  // Copyright (c) 2006 Nero AG and its licensors.
  2.  // All rights reserved.
  3.   
  4.   //////////////////////////// COMMON DESCRIPTIONS //////////////////////////
  5.   //
  6.   // This script consists of several modules, that correspond to a part of the
  7.   // functionality. The modules encapsulate their functions, please consider
  8.   // adding new functions to the corresponding module.
  9.   //
  10.   // Module list:
  11.   // 1)  Nero translation for scripts
  12.   //     The translation of the script is done during translation of the html
  13.   //     page. So I think you'll have nothing to do with this part.
  14.   // 2)  Animation module
  15.   //     This module displays the background animations, e.g. burning, 
  16.   //     verifying, ripping etc.
  17.   // 3)  Status handling module
  18.   //     This module changes the animation, buttons and other components 
  19.   //     depending on current status changes, depending on the values, coming
  20.   //     from the gadget COM server 
  21.   // 4)  The slider module
  22.   //     This module handles the flyouts and dialogs (that are shown inside
  23.   //     the fly-out)
  24.   // 5)  The common button module
  25.   //     This module contains common functions for buttons
  26.   // 6)  The main button module
  27.   //     Specific funtions for the main button (copy/cancel)
  28.   // 7)  The increment copies button module
  29.   //     Specific funtions for the increment copies button
  30.   // 8)  The decrement copies button module
  31.   //     Specific functions for the decrement copies button
  32.   // 9)  Digits Module
  33.   //     Common functions for showing the digits inside the display
  34.   // 10) Display module
  35.   //     This module contains specific functions to update the display
  36.   //     (the percentage, copies number etc)
  37.   // 11) The COM server Module
  38.   //     This module wraps the COM server, which provides the core 
  39.   //     funtionality of the gadget (the burning itself)
  40.   // 12) Initialization module
  41.   //     Contains functions related to the startup of the gadget
  42.   //
  43.   //
  44.  
  45.   // Authors:
  46.   // -------------------------
  47.   // Alexander Hofmann
  48.   // Hans Werner
  49.   // Vitalij Polovinkin
  50.   // ...
  51.   // Person in charge: Alexander Hofmann
  52.   // Product Management: Alexander Gold
  53.  
  54.   var PersistentFileName;
  55.   
  56.   
  57.   ////////////////////////////// translation module //////////////////////////////////
  58.   function RemoveLanguageTags(s)
  59.   {
  60.     return s.replace("#L_#","").replace("#_L#","");
  61.   }
  62.  
  63.   ////////////////////////////// amimation module ////////////////////////////////////
  64.   
  65.   /// This method loads frames of an animation into an array and returns it.
  66.   /// @param Dir The relative directory of the animation
  67.   /// @param Prefix The prefix of the file name
  68.   /// @param Extension The Extension of the frames in the animation
  69.   /// @param Count The number of Pictures in the animation
  70.   /// @return an array with frames of the animation
  71.   function SetupAnimation(Dir,Prefix,Extension,Count)
  72.   {
  73.     var v = new Array();
  74.     for (i=1;i<=Count;i++)
  75.       v[i-1] = "images/" + Dir + Prefix + ((i<10)?"0":"")+ i + Extension;
  76.     return v;
  77.   };
  78.  
  79.   /// Showing that a writable disc is present 
  80.   var WritableDiscAnimation = SetupAnimation("","NDCG_main_opt_actual_Idle _writeable disc_ ",".png",1);
  81.   /// Showing that a readonly disc is present
  82.   var ReadOnlyDiscAnimation = SetupAnimation("","NDCG_main_opt_actual_Idle _read-only disc_ ",".png",1);
  83.   /// showing that no discs present
  84.   var NoDiscAnimation = SetupAnimation("","NDCG_main_opt_actual_Idle _no disc_ ",".png",1);
  85.   /// the ripping animation
  86.   var RippingAnimation = SetupAnimation("Ripping/","NDCG_main_opt_actual_",".png",30);
  87.   /// finalizing disc
  88.   var FinalizingAnimation = SetupAnimation("Finalizing/","NDCG_main_opt_actual_",".png",30);
  89.   /// verifying
  90.   var VerifyingAnimation = SetupAnimation("Importing - Reading - Preparing - Verifying/","NDCG_main_opt_actual_",".png",30);
  91.  
  92.   /// the burning animations (red)
  93.   var BurningAnimation = new Array();
  94.       BurningAnimation[0]=SetupAnimation("Burning 01-10/","NDCG_main_opt_actual_",".png",30);
  95.       BurningAnimation[1]=SetupAnimation("Burning 11-20/","NDCG_main_opt_actual_",".png",30);
  96.       BurningAnimation[2]=SetupAnimation("Burning 21-30/","NDCG_main_opt_actual_",".png",30);
  97.       BurningAnimation[3]=SetupAnimation("Burning 31-40/","NDCG_main_opt_actual_",".png",30);
  98.       BurningAnimation[4]=SetupAnimation("Burning 41-50/","NDCG_main_opt_actual_",".png",30);
  99.       BurningAnimation[5]=SetupAnimation("Burning 51-60/","NDCG_main_opt_actual_",".png",30);
  100.       BurningAnimation[6]=SetupAnimation("Burning 61-70/","NDCG_main_opt_actual_",".png",30);
  101.       BurningAnimation[7]=SetupAnimation("Burning 71-80/","NDCG_main_opt_actual_",".png",30);
  102.       BurningAnimation[8]=SetupAnimation("Burning 81-90/","NDCG_main_opt_actual_",".png",30);
  103.       BurningAnimation[9]=SetupAnimation("Burning 91-100/","NDCG_main_opt_actual_",".png",30);
  104.       BurningAnimation[10]=FinalizingAnimation;
  105.   /// finalizing disc
  106.   var FinalizingAnimationBlue = SetupAnimation("Blue Finalizing/","NDCG_main_opt_actual_",".png",30);
  107.   /// the burning animations (blue)
  108.   var BurningAnimationBlue = new Array();
  109.       BurningAnimationBlue[0]=SetupAnimation("Blue Burning 01-10/","NDCG_main_opt_actual_",".png",30);
  110.       BurningAnimationBlue[1]=SetupAnimation("Blue Burning 11-20/","NDCG_main_opt_actual_",".png",30);
  111.       BurningAnimationBlue[2]=SetupAnimation("Blue Burning 21-30/","NDCG_main_opt_actual_",".png",30);
  112.       BurningAnimationBlue[3]=SetupAnimation("Blue Burning 31-40/","NDCG_main_opt_actual_",".png",30);
  113.       BurningAnimationBlue[4]=SetupAnimation("Blue Burning 41-50/","NDCG_main_opt_actual_",".png",30);
  114.       BurningAnimationBlue[5]=SetupAnimation("Blue Burning 51-60/","NDCG_main_opt_actual_",".png",30);
  115.       BurningAnimationBlue[6]=SetupAnimation("Blue Burning 61-70/","NDCG_main_opt_actual_",".png",30);
  116.       BurningAnimationBlue[7]=SetupAnimation("Blue Burning 71-80/","NDCG_main_opt_actual_",".png",30);
  117.       BurningAnimationBlue[8]=SetupAnimation("Blue Burning 81-90/","NDCG_main_opt_actual_",".png",30);
  118.       BurningAnimationBlue[9]=SetupAnimation("Blue Burning 91-100/","NDCG_main_opt_actual_",".png",30);
  119.       BurningAnimationBlue[10]=FinalizingAnimationBlue;
  120.  
  121.   /// this animation is shown on disc erase      
  122.   var ErasingAnimation = new Array();
  123.   for (i=0;i<30;++i) ErasingAnimation[i]=BurningAnimation[(i - i%3)/3][i];
  124.   for (i=0;i<29;++i) ErasingAnimation[58-i]=BurningAnimation[(i - i%3)/3][i];
  125.   
  126.  /// current animation frame index
  127.   var CurrentAnimationFrame = 0;
  128.   /// current animation
  129.   var CurrentAnimationLoop = RippingAnimation;
  130.   /// what should be executed when the animation is going to the end and starting from the beginning
  131.   var CurrentAnimationRestart = "";
  132.   /// is the animation running
  133.   var bRunning = false;
  134.  
  135.  
  136.   /// the com server, implementing the burning functionality
  137.   var COMServer = null;
  138.   
  139.   /// returns a working COM Server (for the case the server accidently died)
  140.   function SafeCOMServer()
  141.   {
  142.      // first check, if there was a COM server at all.
  143.      if (COMServer == null)
  144.        return null;
  145.        
  146.      try {
  147.        COMServer.GetShowAnimations();
  148.      } catch(e)
  149.      {
  150.        // if there is an error we assume that COM Server died.
  151.        COMServer = null;
  152.        reset();
  153.      };
  154.      return COMServer;
  155.   }
  156.  
  157.   /// main function for showing animations
  158.   /// @param bRepeat true, if the animation should be repeated
  159.   function animation(bRepeat)
  160.   {
  161.      // should we continue the animation
  162.      var bContinue = bRepeat;
  163.      if (CurrentAnimationFrame>=CurrentAnimationLoop.length)
  164.        CurrentAnimationFrame=0;
  165.      else
  166.        bContinue = true;
  167.  
  168.      if ((SafeCOMServer()==null) || (!SafeCOMServer().GetShowAnimations()))
  169.      {
  170.        CurrentAnimationFrame = 0;
  171.        bContinue = false;
  172.      }
  173.  
  174.      // change the image source
  175.      System.Gadget.background = "url(" + CurrentAnimationLoop[CurrentAnimationFrame++] + ")";
  176.  
  177.      // set timeout for further actions
  178.      if (bContinue && (CurrentAnimationLoop.length > 1))
  179.      {
  180.         bRunning=true;
  181.         setTimeout( "animation("+bRepeat+")", 100 );
  182.         if (CurrentAnimationFrame>=CurrentAnimationLoop.length)
  183.           setTimeout( CurrentAnimationRestart,1);
  184.      }
  185.      else
  186.      {
  187.         bRunning=false;
  188.      }
  189.   };
  190.  
  191.   ////////////////////////////////// status handling module ////////////////////////////////
  192.  
  193.   /// we are in burn process
  194.   var bBurning = false;
  195.   /// we were in burn process
  196.   var bLastBurning = false;
  197.   /// the burn progress in procent
  198.   var iProgressPercent = 0;
  199.   /// we are we in ripping
  200.   var bRipping = false;
  201.   /// we were we in ripping
  202.   var bLastRipping = false;
  203.   /// do we have a disc in the destination drive
  204.   var bDiscPresent = false;
  205.   /// is the disc in the destination drive writable
  206.   var bWritableDisc = false;
  207.   /// didi we have a disc in the destination drive
  208.   var bLastDiscPresent = false;
  209.   /// was the disc in the destination drive writable
  210.   var bLastWritableDisc = false;
  211.   /// are we in verifying
  212.   var bReading = false;
  213.   /// were we in verifying
  214.   var bLastVerifying = false;
  215.   /// are we in idle state
  216.   var bIdle = true;
  217.  
  218.   /// updating status of the process. changes animations according to current variables
  219.   function UpdateStatus()
  220.   {
  221.      setTimeout("UpdateStatus()",500);
  222.  
  223.      COMServerTimer();
  224.      
  225.      /// let's decide which animation we want to show
  226.      if (bBurning && !bModalDialog) // burning animations
  227.      {
  228.  
  229.         // first set restart
  230.         if (SafeCOMServer().IsBurningBluRay())
  231.           CurrentAnimationRestart="CurrentAnimationLoop=BurningAnimationBlue["+((iProgressPercent-iProgressPercent%10)/10)+"];CurrentAnimationRestart=\"\";";
  232.         else
  233.           CurrentAnimationRestart="CurrentAnimationLoop=BurningAnimation["+((iProgressPercent-iProgressPercent%10)/10)+"];CurrentAnimationRestart=\"\";";
  234.  
  235.         // afterwards if the last animation ended - start a new one.
  236.         if (!bRunning)
  237.         {
  238.            if (SafeCOMServer().IsBurningBluRay())
  239.              CurrentAnimationLoop=BurningAnimationBlue[(iProgressPercent-iProgressPercent%10)/10];
  240.            else
  241.              CurrentAnimationLoop=BurningAnimation[(iProgressPercent-iProgressPercent%10)/10];
  242.            CurrentAnimationRestart="";
  243.            animation(true);
  244.         }
  245.      } else
  246.      if (bRipping && !bModalDialog) // ripping animation
  247.      {
  248.         
  249.         // first set restart
  250.         CurrentAnimationRestart="CurrentAnimationLoop=RippingAnimation;CurrentAnimationRestart=\"\";";
  251.  
  252.         // afterwards if the last animation ended - start a new one.
  253.         if (!bRunning)
  254.         {
  255.            CurrentAnimationLoop=RippingAnimation;
  256.            CurrentAnimationRestart="";
  257.            animation(true);
  258.         }
  259.       } else
  260.       if (bReading && !bModalDialog) // verification animation
  261.       {
  262.         
  263.         // first set restart
  264.         CurrentAnimationRestart="CurrentAnimationLoop=VerifyingAnimation;CurrentAnimationRestart=\"\";";
  265.  
  266.         // afterwards if the last animation ended - start a new one.
  267.         if (!bRunning)
  268.         {
  269.            CurrentAnimationLoop=VerifyingAnimation;
  270.            CurrentAnimationRestart="";
  271.            animation(true);
  272.         }
  273.       } else 
  274.       if (bWritableDisc) // no further animations present, just stills
  275.       {
  276.         if (!bLastWritableDisc)
  277.             AddMessage(RemoveLanguageTags(L_BurnanbleDisc));
  278.         // first set restart
  279.         //CurrentAnimationRestart="CurrentAnimationLoop=WritableDiscAnimation;CurrentAnimationRestart=\"\";";
  280.         CurrentAnimationLoop=WritableDiscAnimation;CurrentAnimationRestart="";
  281.  
  282.         // afterwards if the last animation ended - start a new one.
  283.         if (!bRunning)
  284.         {
  285.            CurrentAnimationLoop=WritableDiscAnimation;
  286.            CurrentAnimationRestart="";
  287.            animation(false); //after the end of the animation don't repeat it from the start
  288.         }
  289.       } else
  290.       if (bDiscPresent) 
  291.       {
  292.         if (!bLastDiscPresent)
  293.         AddMessage(RemoveLanguageTags(L_ReadonlyDisc));
  294.         
  295.         // first set restart
  296.         //CurrentAnimationRestart="CurrentAnimationLoop=ReadOnlyDiscAnimation;CurrentAnimationRestart=\"\";";
  297.         CurrentAnimationLoop=ReadOnlyDiscAnimation;CurrentAnimationRestart="";
  298.  
  299.         // afterwards if the last animation ended - start a new one.
  300.         if (!bRunning)
  301.         {
  302.            CurrentAnimationLoop=ReadOnlyDiscAnimation;
  303.            CurrentAnimationRestart="";
  304.            animation(false); //after the end of the animation don't repeat it from the start
  305.         }
  306.       } else
  307.       {
  308.         if (bLastDiscPresent)
  309.           AddMessage(RemoveLanguageTags(L_NoDisc));
  310.         // first set restart
  311.         CurrentAnimationRestart="CurrentAnimationLoop=NoDiscAnimation;CurrentAnimationRestart=\"\";";
  312.  
  313.         // afterwards if the last animation ended - start a new one.
  314.         if (!bRunning)
  315.         {
  316.            CurrentAnimationLoop=NoDiscAnimation;
  317.            CurrentAnimationRestart="";
  318.            animation(false); //after the end of the animation don't repeat it from the start
  319.         };
  320.      };
  321.      bLastWritableDisc = bWritableDisc;
  322.      bLastDiscPresent = bDiscPresent;
  323.      bLastBurning = bBurning;
  324.      bLastVerifying = bReading;
  325.      bLastRipping = bRipping;
  326.      bIdle=!bRipping && !bReading && !bBurning;
  327.      // update also the main button
  328.      UpdateMainButton();
  329.      // and the display
  330.      UpdateDisplay();
  331.   };
  332.  
  333.  
  334.   ///////////////////////////// The deatils slider module ///////////////////////////////
  335.   /// current slide animation
  336.   var slideAnimation = 1;
  337.   /// current stretch width of the slideout area
  338.   var stretchWidth = 5;
  339.   /// delta-x for slide-out animation
  340.   var delta = 5;
  341.   /// is there a modal dialog present?
  342.   var bModalDialog = false;
  343.   /// the index of the current message
  344.   var iMessageIndex = 0;
  345.   /// first (earliest) message in the buffer
  346.   var Messages = new Array();
  347.   /// The modal dialog (header, bold)
  348.   var DialogHeading="";
  349.   /// The modal dialog message
  350.   var DialogMessage="";
  351.   /// current status text (for checking, if it was already shown in a message)
  352.   var strCurrentStatusText="";
  353.   /// current index of the request to show the slide out
  354.   var iAppearanceIndex=0;
  355.   /// current index of the request to hide the slide out
  356.   var iHidingIndex = 0;
  357.  
  358.   /// shows details (in the flyout area)
  359.   function ShowDetails()
  360.   {
  361.     ++iAppearanceIndex;
  362.     if (!System.Gadget.Flyout.show)
  363.         System.Gadget.Flyout.show = true;
  364.   };
  365.  
  366.    /// hides details (in the flyout area)
  367.    function HideDetails()
  368.    {
  369.     if (System.Gadget.Flyout.show)
  370.         System.Gadget.Flyout.show = false;
  371.     ++iHidingIndex;
  372.    };
  373.  
  374.     /// setups the flyout animation to slide in, if current message is equal
  375.     /// @param index the index of the message to compare with
  376.     function ConditionalSlideIn(index)
  377.     {
  378.        if ((iMessageIndex==index)&&(!bModalDialog))
  379.          HideDetails();
  380.     };
  381.  
  382.     /// setups the flyout animation to slide in, if current message is equal
  383.     /// @param index the AppearanceIndex to compare with
  384.     function ConditionalSlideIn2(index)
  385.     {
  386.        if ((iAppearanceIndex==index)&&(!bModalDialog))
  387.          HideDetails();
  388.     };
  389.  
  390.     /// calls slidein after a period of time
  391.     function DelaySlideIn()
  392.     {
  393.         ++iHidingIndex;
  394.         setTimeout('HideDetails()', 2500);
  395.     };
  396.     
  397.     /// slides in if there was nobody else calling SlideOut afterwards;
  398.     function AutoSlideIn()
  399.     {
  400.         ++iHidingIndex;
  401.         setTimeout("ConditionalSlideIn2("+iAppearanceIndex+")", 2500);
  402.     }
  403.  
  404.     /// calls slideout after a period of time
  405.     function DelaySlideOut()
  406.     {
  407.         ++iAppearanceIndex;
  408.         setTimeout('ShowDetails()', 180);
  409.     };
  410.     
  411.     /// setups the flyout animation to slide out, if current message is equal
  412.     /// @param index the HidingIndex of to compare with
  413.     function ConditionalSlideOut(index)
  414.     {
  415.       if ((iHidingIndex==index)||(bModalDialog))
  416.         ShowDetails();
  417.     }    
  418.     
  419.     // slides out if there was nobody calling slidein afterwards;
  420.     function AutoSlideOut()
  421.     {
  422.        ++iAppearanceIndex;
  423.        if (bModalDialog)
  424.          setTimeout("ConditionalSlideOut("+iHidingIndex+")", 500);
  425.        else
  426.          setTimeout("ConditionalSlideOut("+iHidingIndex+")", 2000);
  427.     }
  428.     
  429.   /// shows last log messages
  430.   function ShowMessages()
  431.   {
  432.      try {
  433.         OnShowMessages();
  434.      } catch (e) { /* ignore */ };
  435.      System.Gadget.Flyout.onShow = OnShowMessages;
  436.      ShowDetails();
  437.   };
  438.   
  439.   /// this is called when the flyout is shown with messages
  440.   function OnShowMessages()
  441.   {
  442.     if (!System.Gadget.Flyout.show || bModalDialog)
  443.       return;
  444.       
  445.     LastDialogText = "";
  446.     var text =  '<table border="0" width="80%">\r\n';
  447.     var i;
  448.     for (i=Messages.length-1;i>=0;--i)
  449.     {
  450.        text = text + '<tr style="cursor:default; font-size: 12px;"><td><font color="black"><b>'
  451.                    + (iMessageIndex-Messages.length+1+i) + ". "+ Messages[i] 
  452.                    + "</b></font></td></tr>\r\n";
  453.     };
  454.     text = text + "</table>";
  455.     System.Gadget.Flyout.document.getElementById("Log").innerHTML = text;
  456.     SetupFlyoutCallbacks();
  457.   }
  458.   
  459.   /// this is called when the flyout is shown with the initial screen with versions
  460.   function OnShowVersion()
  461.   {
  462.     if (!System.Gadget.Flyout.show || bModalDialog)
  463.       return;
  464.       
  465.     System.Gadget.Flyout.document.getElementById("Version").innerHTML = 
  466.         RemoveLanguageTags(L_Version) + " " + System.Gadget.version + "<br />" +
  467.         RemoveLanguageTags(L_VersionServer) + " " + SafeCOMServer().GetServerVersion(0) + "." + SafeCOMServer().GetServerVersion(1) + "." + SafeCOMServer().GetServerVersion(2) + "." + SafeCOMServer().GetServerVersion(3) + "<br />" +
  468.         RemoveLanguageTags(L_VersionAPI) + " " + SafeCOMServer().GetNeroAPIVersion(0) + "." + SafeCOMServer().GetNeroAPIVersion(1) + "." + SafeCOMServer().GetNeroAPIVersion(2) + "." + SafeCOMServer().GetNeroAPIVersion(3) + "<br />";
  469.         
  470.     SetupFlyoutCallbacks();
  471.   }
  472.   
  473.   /// sets callbacks for the flyout elements so the flyout doesn't disappear too quickly
  474.   function SetupFlyoutCallbacks()
  475.   {
  476.     var i;
  477.     for (i=0;i<System.Gadget.Flyout.document.all.length;++i)
  478.     {
  479.         if (System.Gadget.Flyout.document.all[i].onmouseover == null)
  480.           System.Gadget.Flyout.document.all[i].onmouseover = AutoSlideOut;
  481.         if (System.Gadget.Flyout.document.all[i].onmouseout == null)
  482.           System.Gadget.Flyout.document.all[i].onmouseout = AutoSlideIn;
  483.     };    
  484.   }
  485.    
  486.   /// shows dialog contents
  487.   function ShowDialog()
  488.   {
  489.      bModalDialog=true;
  490.      try {
  491.         RefreshDialog();
  492.      } catch (e) { /* ignore */ };
  493.      System.Gadget.Flyout.onShow = OnShowDialog;
  494.      ShowDetails();
  495.   };
  496.   
  497.   var WAITCD_POPUP_BUTTON_OK      = 4;
  498.   var WAITCD_POPUP_BUTTON_STOP    = 8;
  499.   var WAITCD_POPUP_BUTTON_LOAD    = 16;
  500.   var WAITCD_POPUP_BUTTON_ERASE   = 32;
  501.   var LastDialogText = "";
  502.  
  503.  
  504.   /// this is called when the flyout is shown with a dialog
  505.   function RefreshDialog()
  506.   {
  507.     var stat = COMServer.GetWaitCDPopupStatus();
  508.     var Buttons = (((stat&WAITCD_POPUP_BUTTON_OK)!=0)?'<button onclick="Log.COMServer.SetWaitCDPopupResult('+WAITCD_POPUP_BUTTON_OK+')">'+RemoveLanguageTags(L_Ok)+'</button>':'')+
  509.                   (((stat&WAITCD_POPUP_BUTTON_LOAD)!=0)?'<button onclick="Log.COMServer.SetWaitCDPopupResult('+WAITCD_POPUP_BUTTON_LOAD+')">'+RemoveLanguageTags(L_CloseTray)+'</button>':'')+
  510.                   (((stat&WAITCD_POPUP_BUTTON_ERASE)!=0)?'<button onclick="Log.COMServer.SetWaitCDPopupResult('+WAITCD_POPUP_BUTTON_ERASE+')">'+RemoveLanguageTags(L_EraseDisc)+'</button>':'')+
  511.                   (((stat&WAITCD_POPUP_BUTTON_STOP)!=0)?'<button onclick="Log.COMServer.SetWaitCDPopupResult('+WAITCD_POPUP_BUTTON_STOP+')">'+RemoveLanguageTags(L_Cancel)+'</button>':'');
  512.     var text = '<b><font color="Black">'+DialogHeading+'</font></b><br/>' + DialogMessage + '<br/>' + Buttons;
  513.     if (text!=LastDialogText)
  514.         System.Gadget.Flyout.document.getElementById("Log").innerHTML = text;
  515.     
  516.     SetupFlyoutCallbacks();    
  517.     
  518.     System.Gadget.Flyout.document.getElementById("Log").COMServer = COMServer;
  519.     LastDialogText=text;
  520.   }
  521.  
  522.   /// this is called when the flyout is shown with a dialog
  523.   function OnShowDialog()
  524.   {
  525.     LastDialogText="";
  526.     RefreshDialog();
  527.   }
  528.   
  529.  
  530.   /// adds a message to the log
  531.   /// @param s the new message
  532.   function AddMessage(s)
  533.   {
  534.     var i;
  535.     if (iMessageIndex>=100)
  536.     {
  537.       for (i = 0; i<99; ++i)
  538.         Messages[i] = Messages[i+1];
  539.       Messages[99] = s;
  540.     } else
  541.       Messages[iMessageIndex] = s;
  542.     iMessageIndex++;
  543.     
  544.     if (!bModalDialog)
  545.     {
  546.       System.Gadget.Flyout.onShow = OnShowMessages;
  547.       if ((SafeCOMServer()==null) || (SafeCOMServer().GetVerboseMode() || System.Gadget.Flyout.show))
  548.       {
  549.         ShowMessages();
  550.         if (!System.Gadget.Flyout.show)
  551.             setTimeout("ConditionalSlideIn("+iMessageIndex+")", 5000);
  552.       };
  553.     };
  554.   };
  555.   
  556.   /// Clears all Messages
  557.   function ClearMessages()
  558.   {
  559.     iMessageIndex = 0; 
  560.     Messages = new Array();
  561.   }
  562.   
  563.   /// this function checks if last shown status text should be updated
  564.   /// in this case it adds a new log message
  565.   /// @param strText: current status text
  566.   function CheckCurrentStatusText(strText)
  567.   {
  568.     if (strCurrentStatusText!=strText)
  569.     {
  570.       strCurrentStatusText=strText;
  571.       AddMessage(strText);
  572.     }
  573.   }
  574.   
  575.   //////////////////////// the common button module /////////////////////////
  576.   /// the enumeration constant for an idle button
  577.   var eButtonIdle = 0;
  578.   /// the enumeration constant for a disabled button
  579.   var eButtonDisabled = 1;
  580.   /// the enumeration constant for a pressed button
  581.   var eButtonPressed = 2;
  582.   /// the enumeration constant for a hover button
  583.   var eButtonHover = 3;
  584.   
  585.   /// Prepares a button (loads needed images)
  586.   /// @param strPrefix The Prefix for the location of the button images (e.g. "images/test_")
  587.   /// @param strPostfix The postfix for the location of the button images (e.g. ".png")
  588.   function PrepareButton(strPrefix,strSuffix)
  589.   {
  590.     var temp=new Array();
  591.     temp[eButtonIdle]=new Image();
  592.     temp[eButtonIdle].src=strPrefix+"Idle"+strSuffix;
  593.     temp[eButtonDisabled]=new Image();
  594.     temp[eButtonDisabled].src=strPrefix+"Disabled"+strSuffix;
  595.     temp[eButtonPressed]=new Image();
  596.     temp[eButtonPressed].src=strPrefix+"Pressed"+strSuffix;
  597.     temp[eButtonHover]=new Image();
  598.     temp[eButtonHover].src=strPrefix+"Hover"+strSuffix;
  599.     return temp;
  600.   };
  601.   
  602.   //////////////////////// the main button module ///////////////////////////
  603.   /// the images for the copy button
  604.   var CopyButton = PrepareButton("images/Copy Mode/Copy Button/NDCG_main_opt_actual_",".png");
  605.   /// the images for the cancel button
  606.   var CancelButton = PrepareButton("images/Cancel Mode/Cancel Button/NDCG_main_opt_actual_",".png");
  607.  
  608.   /// is true if the mouse is over the main button
  609.   var bOverMainButton = false;
  610.   /// is true if the mouse is pressed
  611.   var bMainButtonPressed = false;
  612.   /// current status index
  613.   var iCurrentMainButtonStatusIndex = 0;
  614.   /// was the last button the copy button?
  615.   var bLastCopyButton = true;
  616.   /// allow pressing the button? this shouldn't always be possible, especially, on button functionality changes
  617.   var bMainButtonAllowed = true;
  618.  
  619.  
  620.   // conditionally allows the main button
  621.   function ConditionallyAllowButton(index)
  622.   {
  623.     if (iCurrentMainButtonStatusIndex==index)
  624.     {
  625.        bMainButtonAllowed = true;
  626.        UpdateMainButton();
  627.     }
  628.   }
  629.  
  630.   /// updates the image on the main button
  631.   function UpdateMainButton()
  632.   {
  633.      var CurrentImageSet;
  634.      if (bIdle || bModalDialog)
  635.      {
  636.        // in this case we want to show the copy button
  637.        CurrentImageSet=CopyButton;
  638.        if (bModalDialog)
  639.           MainButtonImg.alt=RemoveLanguageTags(L_Ok);
  640.        else
  641.           MainButtonImg.alt=RemoveLanguageTags(L_Copy);
  642.        if (!bLastCopyButton)
  643.        {
  644.           ++iCurrentMainButtonStatusIndex;
  645.           bMainButtonAllowed=false;
  646.           setTimeout("ConditionallyAllowButton("+iCurrentMainButtonStatusIndex+")",3000);
  647.           bLastCopyButton=true;
  648.        }
  649.      }
  650.      else
  651.      {
  652.        // in this case we want to show the cancel button
  653.        MainButtonImg.alt=RemoveLanguageTags(L_Cancel);
  654.        CurrentImageSet=CancelButton;
  655.        if (bLastCopyButton)
  656.        {
  657.           ++iCurrentMainButtonStatusIndex;
  658.           bMainButtonAllowed=false;
  659.           setTimeout("ConditionallyAllowButton("+iCurrentMainButtonStatusIndex+")",3000);
  660.           bLastCopyButton=false;
  661.        }
  662.      }
  663.  
  664.      if (!bMainButtonAllowed || (bIdle && (GetCopies()==0)))
  665.        MainButtonImg.src = CurrentImageSet[eButtonDisabled].src;
  666.      else
  667.      if (bOverMainButton)
  668.        if (bMainButtonPressed)
  669.          MainButtonImg.src = CurrentImageSet[eButtonPressed].src;
  670.        else
  671.          MainButtonImg.src = CurrentImageSet[eButtonHover].src;
  672.      else
  673.        MainButtonImg.src = CurrentImageSet[eButtonIdle].src;
  674.   };
  675.  
  676.   /// this is called by the framework when the mouse is over the main button
  677.   function MouseOverMainButton()
  678.   {
  679.     bOverMainButton=true;
  680.     UpdateMainButton();
  681.   };
  682.  
  683.   /// this is called by the framework when the mouse is out of the main button
  684.   function MouseOutOfMainButton()
  685.   {
  686.     bOverMainButton=false;
  687.     UpdateMainButton();
  688.   };
  689.  
  690.   /// this is called by the framework when the mouse is pressed on the main button
  691.   function MainButtonMouseDown()
  692.   {
  693.     bMainButtonPressed=true;
  694.     UpdateMainButton();
  695.   };
  696.  
  697.   /// this is called by the framework when the mouse is released on the main button
  698.   function MainButtonMouseUp()
  699.   {
  700.     bMainButtonPressed=false;
  701.     UpdateMainButton();
  702.   };
  703.  
  704.   /// this is called by the framework when the mouse clicked on the main button
  705.   function MainButtonClicked()
  706.   {
  707.     // don't allow the user to click on the button when it just changed
  708.     if (!bMainButtonAllowed)
  709.       return;
  710.  
  711.     COMServerDebugText( "MainButtonClicked()" );
  712.     
  713.     if (bModalDialog)
  714.         OnOk();
  715.     else
  716.         if (!bIdle)
  717.             CancelCopy();
  718.         else
  719.             StartCopy();
  720.   };
  721.   
  722.   
  723.   ////////////////////////// increment copies buttons module ///////////////////////////
  724.  
  725.   var bOverIncCopiesButton = false;
  726.   var bIncCopiesButtonPressed = false;
  727.   var IncCopiesImageSet = PrepareButton("images/Copy Mode/Copies Plus/NDCG_main_opt_actual_",".png");
  728.   var iCurrentCopiesMessageIndex = 0;
  729.   var iCurrentDelay = 0;
  730.   var bIncrement = false;
  731.  
  732.   function AutoIncrementDecrement(iMessageIndex)
  733.   {
  734.      if (iMessageIndex == iCurrentCopiesMessageIndex)
  735.      {
  736.         if (iCurrentDelay!=0)
  737.         {
  738.             if (bIncrement)
  739.             {
  740.                 if (GetCopies()<=99)
  741.                 {
  742.                   IncCopies();
  743.                   UpdateDisplay();
  744.                   setTimeout("AutoIncrementDecrement("+iMessageIndex+")",iCurrentDelay);
  745.                 }
  746.             } else
  747.             {
  748.                 if (GetCopies()>1)
  749.                 {
  750.                   DecCopies();
  751.                   UpdateDisplay();
  752.                   setTimeout("AutoIncrementDecrement("+iMessageIndex+")",iCurrentDelay);
  753.                 }
  754.             }
  755.         };          
  756.      }
  757.   }
  758.  
  759.   function StartIncrementDecrement(iMessageIndex,iDelay,bInc)
  760.   {
  761.      if (iMessageIndex == iCurrentCopiesMessageIndex)
  762.      {
  763.         bIncrement=bInc;
  764.         if (iCurrentDelay!=0)
  765.         {
  766.             iCurrentDelay = iDelay;
  767.         } else
  768.         {
  769.             iCurrentDelay = iDelay;
  770.             AutoIncrementDecrement(iMessageIndex);
  771.         }
  772.      }
  773.   }
  774.  
  775.   /// this is called by the framework when the mouse is over the increment copies button
  776.   function MouseOverIncCopiesButton()
  777.   {
  778.     bOverIncCopiesButton=true;
  779.     UpdateIncCopiesButton();
  780.     iCurrentDelay=0;
  781.     ++iCurrentCopiesMessageIndex;
  782.   };
  783.  
  784.   /// this is called by the framework when the mouse is out of the increment copies button
  785.   function MouseOutOfIncCopiesButton()
  786.   {
  787.     bOverIncCopiesButton=false;
  788.     UpdateIncCopiesButton();
  789.     iCurrentDelay=0;
  790.     ++iCurrentCopiesMessageIndex;
  791.   };
  792.  
  793.   /// this is called by the framework when the mouse is pressed on the increment copies button
  794.   function IncCopiesButtonMouseDown()
  795.   {
  796.     bIncCopiesButtonPressed=true;
  797.     UpdateIncCopiesButton();
  798.     ++iCurrentCopiesMessageIndex;
  799.     iCurrentDelay=0;
  800.     setTimeout("StartIncrementDecrement("+iCurrentCopiesMessageIndex+",500,true)",500);
  801.     setTimeout("StartIncrementDecrement("+iCurrentCopiesMessageIndex+",250,true)",2000);
  802.     setTimeout("StartIncrementDecrement("+iCurrentCopiesMessageIndex+",125,true)",4000);
  803.   };
  804.  
  805.   /// this is called by the framework when the mouse is released on the increment copies button
  806.   function IncCopiesButtonMouseUp()
  807.   {
  808.     bIncCopiesButtonPressed=false;
  809.     UpdateIncCopiesButton();
  810.     ++iCurrentCopiesMessageIndex;
  811.   };
  812.  
  813.   /// this is called by the framework when the mouse clicked on the increment copies button
  814.   function IncCopiesButtonClicked()
  815.   {
  816.     if (GetCopies()<=99)
  817.     {
  818.       IncCopies();
  819.       UpdateDisplay();
  820.     }
  821.     iCurrentDelay=0;
  822.     ++iCurrentCopiesMessageIndex;
  823.   };
  824.  
  825.   /// updates the image on the main button
  826.   function UpdateIncCopiesButton()
  827.   {
  828.      if (GetCopies()>=99)
  829.        IncCopiesImg.src = IncCopiesImageSet[eButtonDisabled].src;
  830.      else
  831.      if (bOverIncCopiesButton)
  832.        if (bIncCopiesButtonPressed)
  833.          IncCopiesImg.src = IncCopiesImageSet[eButtonPressed].src;
  834.        else
  835.          IncCopiesImg.src = IncCopiesImageSet[eButtonHover].src;
  836.      else
  837.        IncCopiesImg.src = IncCopiesImageSet[eButtonIdle].src;
  838.   };
  839.  
  840.  
  841.   ////////////////////////// decrement copies buttons module ///////////////////////////
  842.  
  843.   var bOverDecCopiesButton = false;
  844.   var bDecCopiesButtonPressed = false;
  845.   var DecCopiesImageSet = PrepareButton("images/Copy Mode/Copies Minus/NDCG_main_opt_actual_",".png");
  846.   
  847.   /// this is called by the framework when the mouse is over the decrement copies button
  848.   function MouseOverDecCopiesButton()
  849.   {
  850.     bOverDecCopiesButton=true;
  851.     UpdateDecCopiesButton();
  852.     ++iCurrentCopiesMessageIndex;
  853.     iCurrentDelay=0;
  854.   };
  855.  
  856.   /// this is called by the framework when the mouse is out of the decrement copies button
  857.   function MouseOutOfDecCopiesButton()
  858.   {
  859.     bOverDecCopiesButton=false;
  860.     UpdateDecCopiesButton();
  861.     ++iCurrentCopiesMessageIndex;
  862.     iCurrentDelay=0;
  863.   };
  864.  
  865.   /// this is called by the framework when the mouse is pressed on the decrement copies button
  866.   function DecCopiesButtonMouseDown()
  867.   {
  868.     bDecCopiesButtonPressed=true;
  869.     UpdateDecCopiesButton();
  870.     ++iCurrentCopiesMessageIndex;
  871.     iCurrentDelay=0;
  872.     setTimeout("StartIncrementDecrement("+iCurrentCopiesMessageIndex+",500,false)",500);
  873.     setTimeout("StartIncrementDecrement("+iCurrentCopiesMessageIndex+",250,false)",2000);
  874.     setTimeout("StartIncrementDecrement("+iCurrentCopiesMessageIndex+",125,false)",4000);
  875.   };
  876.  
  877.   /// this is called by the framework when the mouse is released on the decrement copies button
  878.   function DecCopiesButtonMouseUp()
  879.   {
  880.     bDecCopiesButtonPressed=false;
  881.     UpdateDecCopiesButton();
  882.     iCurrentDelay=0;
  883.     ++iCurrentCopiesMessageIndex;
  884.   };
  885.  
  886.   /// this is called by the framework when the mouse clicked on the decrement copies button
  887.   function DecCopiesButtonClicked()
  888.   {
  889.     if (GetCopies()>1)
  890.     {
  891.       DecCopies();
  892.       UpdateDisplay();
  893.     }
  894.     iCurrentDelay=0;
  895.     ++iCurrentCopiesMessageIndex;
  896.   };
  897.  
  898.  
  899.   /// updates the image on the main button
  900.   function UpdateDecCopiesButton()
  901.   {
  902.      if (GetCopies()<=1)
  903.        DecCopiesImg.src = DecCopiesImageSet[eButtonDisabled].src;
  904.      else
  905.      if (bOverDecCopiesButton)
  906.        if (bDecCopiesButtonPressed)
  907.          DecCopiesImg.src = DecCopiesImageSet[eButtonPressed].src;
  908.        else
  909.          DecCopiesImg.src = DecCopiesImageSet[eButtonHover].src;
  910.      else
  911.        DecCopiesImg.src = DecCopiesImageSet[eButtonIdle].src;
  912.   };
  913.  
  914.   //////////////////////////////// digits module /////////////////////////////////
  915.  
  916.   /// this function loads the pictures of digits
  917.   /// @param strPrefix the prefix for the location of the pictures (e.g. "images/Digit_")
  918.   /// @param strPostfix the postfix for the location of the pictures (e.g. ".png")
  919.   function PrepareDigits(strPrefix,strPostfix)
  920.   {
  921.     var temp = new Array();
  922.     var i;
  923.     for (i = 0; i < 10; ++i)
  924.     {
  925.       temp[i] = new Image();
  926.       temp[i].src = strPrefix+i+strPostfix;
  927.     }
  928.     
  929.     return temp;
  930.   };
  931.   /// the digits to show
  932.   var Digits=PrepareDigits("images/digits/Digit_",".PNG");
  933.   var BlackDigits=PrepareDigits("images/digits/Digit_","b.PNG");
  934.   
  935.   /// shows digits area
  936.   /// @param iNullToNinentyNine The two digits to display
  937.   /// @param bBlack
  938.   function UpdateDigits(iNullToNinetyNine, bBlack)
  939.   {
  940.     var i = iNullToNinetyNine;
  941.     if (iNullToNinetyNine>99)
  942.       i=99;
  943.     if (i<0)
  944.       i=0;
  945.  
  946.     if (bBlack)
  947.     {
  948.       LSDigitImg.src=BlackDigits[i%10].src;
  949.       MSDigitImg.src=BlackDigits[(i-i%10)/10].src;
  950.     } else
  951.     {
  952.       LSDigitImg.src=Digits[i%10].src;
  953.       MSDigitImg.src=Digits[(i-i%10)/10].src;
  954.     }
  955.   };
  956.  
  957.  
  958.   ////////////////////////// The display module /////////////////////////////////
  959.   var CopiesDisplayImage = new Image();
  960.   CopiesDisplayImage.src="images/Copy Mode/Copies Entry/NDCG_main_opt_actual_Entry.png";
  961.   var PercentDisplayImage = new Image();
  962.   PercentDisplayImage.src="images/Copy Mode/Percentage Display/NDCG_main_opt_actual_Display.png";
  963.   
  964.   function UpdateDisplay()
  965.   {
  966.      if (bIdle || bModalDialog)
  967.      {
  968.        if ((SafeCOMServer() != null) && (SafeCOMServer().GetShowCopies()))
  969.        {
  970.             // show number of copies
  971.             UpdateDecCopiesButton();
  972.             UpdateIncCopiesButton();
  973.             DisplayImg.src = CopiesDisplayImage.src;
  974.             LSDigitImg.style.visibility = "visible";
  975.             MSDigitImg.style.visibility = "visible";
  976.             DisplayImg.style.visibility = "visible";
  977.             IncCopiesImg.style.visibility = "visible";
  978.             DecCopiesImg.style.visibility = "visible";
  979.             LSDigitImg.alt = RemoveLanguageTags(L_NumberOfCopies);
  980.             MSDigitImg.alt = RemoveLanguageTags(L_NumberOfCopies);
  981.             DisplayImg.alt = RemoveLanguageTags(L_NumberOfCopies);
  982.             UpdateDigits(GetCopies(),true);
  983.         } else
  984.         {
  985.             IncCopiesImg.style.visibility = "hidden";
  986.             DecCopiesImg.style.visibility = "hidden";
  987.             LSDigitImg.style.visibility = "hidden";
  988.             MSDigitImg.style.visibility = "hidden";
  989.             DisplayImg.style.visibility = "hidden";            
  990.         }
  991.      } else
  992.      {
  993.         // show current progress
  994.        DisplayImg.src = PercentDisplayImage.src;
  995.        LSDigitImg.style.visibility = "visible";
  996.        MSDigitImg.style.visibility = "visible";
  997.        DisplayImg.style.visibility = "visible";            
  998.        IncCopiesImg.style.visibility = "hidden";
  999.        DecCopiesImg.style.visibility = "hidden";
  1000.        LSDigitImg.alt = RemoveLanguageTags(L_Progress);
  1001.        MSDigitImg.alt = RemoveLanguageTags(L_Progress);
  1002.        DisplayImg.alt = RemoveLanguageTags(L_Progress);
  1003.        UpdateDigits(iProgressPercent,false);
  1004.      }
  1005.   };
  1006.  
  1007.  
  1008.   
  1009.   
  1010.   /////////////////////////// com server module ///////////////////////////////////
  1011.  
  1012.   /// the com server, implementing the burning functionality
  1013.   var COMServer = null;
  1014.   /// this is true when the wait for cd dialog is shown
  1015.   var bDialogWaitForCD = false;
  1016.   /// this is true when the popup dialog is shown
  1017.   var bDialogPopup = false;
  1018.   /// this is true if we shown a message, that an error occured
  1019.   var bErrorTextPresent = false;
  1020.  
  1021.   /// the result fo OK button
  1022.   var IDOK          = 4;
  1023.   /// The result for the Cancel button
  1024.   var IDCANCEL      = 8;
  1025.   /// The result for the LoadTray button
  1026.   var IDLOADTRAY    = 16;
  1027.   /// the result for the Erase button
  1028.   var IDERASE       = 32;
  1029.   
  1030.   var NERO_PHASE_ABORT                      = -3;
  1031.   var NERO_PHASE_ERROR                      = -2;
  1032.   var NERO_PHASE_IDLE                       = -1;
  1033.   var NERO_PHASE_BURNING_COMPLETE           = 0;
  1034.   var NERO_PHASE_BURN_PROCESS_STARTED       = 1;
  1035.   var NERO_PHASE_BUILD_IMAGE                = 2;
  1036.   var NERO_PHASE_START_CACHE                = 24;
  1037.   var NERO_PHASE_DONE_CACHE                    = 25;
  1038.   var NERO_PHASE_FAIL_CACHE                    = 26;
  1039.   var NERO_PHASE_ABORT_CACHE                = 27;
  1040.   var NERO_PHASE_START_TEST                    = 28;
  1041.   var NERO_PHASE_DONE_TEST                    = 29;
  1042.   var NERO_PHASE_FAIL_TEST                    = 30;
  1043.   var NERO_PHASE_ABORT_TEST                    = 31;
  1044.   var NERO_PHASE_START_SIMULATE                = 32;
  1045.   var NERO_PHASE_DONE_SIMULATE                = 33;
  1046.   var NERO_PHASE_FAIL_SIMULATE                = 34;
  1047.   var NERO_PHASE_ABORT_SIMULATE                = 35;
  1048.   var NERO_PHASE_START_WRITE                = 36;
  1049.   var NERO_PHASE_DONE_WRITE                    = 37;
  1050.   var NERO_PHASE_FAIL_WRITE                    = 38;
  1051.   var NERO_PHASE_ABORT_WRITE                = 39;
  1052.   var NERO_PHASE_START_SIMULATE_NOSPD        = 61;
  1053.   var NERO_PHASE_DONE_SIMULATE_NOSPD        = 62;
  1054.   var NERO_PHASE_FAIL_SIMULATE_NOSPD        = 63;
  1055.   var NERO_PHASE_ABORT_SIMULATE_NOSPD        = 64;
  1056.   var NERO_PHASE_START_WRITE_NOSPD            = 65;
  1057.   var NERO_PHASE_DONE_WRITE_NOSPD            = 66;
  1058.   var NERO_PHASE_FAIL_WRITE_NOSPD            = 67;
  1059.   var NERO_PHASE_ABORT_WRITE_NOSPD            = 68;
  1060.   var NERO_PHASE_PREPARE_ITEMS                = 73;
  1061.   var NERO_PHASE_VERIFY_COMPILATION            = 78;
  1062.   var NERO_PHASE_VERIFY_ABORTED                = 79;
  1063.   var NERO_PHASE_VERIFY_END_OK                = 80;
  1064.   var NERO_PHASE_VERIFY_END_FAIL            = 81;
  1065.   var NERO_PHASE_ENCODE_VIDEO                = 82;
  1066.   var NERO_PHASE_SEAMLESSLINK_ACTIVATED     = 87;
  1067.   var NERO_PHASE_BUP_ACTIVATED                = 90;  // Generic: Buffer underun protection activated
  1068.   var NERO_PHASE_START_FORMATTING            = 98;
  1069.   var NERO_PHASE_CONTINUE_FORMATTING        = 99;
  1070.   var NERO_PHASE_FORMATTING_SUCCESSFUL        = 100;
  1071.   var NERO_PHASE_FORMATTING_FAILED          = 101;
  1072.   var NERO_PHASE_PREPARE_CD                    = 105;
  1073.   var NERO_PHASE_DONE_PREPARE_CD            = 106;
  1074.   var NERO_PHASE_FAIL_PREPARE_CD            = 107;
  1075.   var NERO_PHASE_ABORT_PREPARE_CD            = 108;
  1076.   var NERO_PHASE_DVDVIDEO_DETECTED            = 111;
  1077.   var NERO_PHASE_DVDVIDEO_REALLOC_STARTED    = 112;
  1078.   var NERO_PHASE_DVDVIDEO_REALLOC_COMPLETED    = 113;
  1079.   var NERO_PHASE_DVDVIDEO_REALLOC_NOTNEEDED    = 114;
  1080.   var NERO_PHASE_DVDVIDEO_REALLOC_FAILED    = 115;
  1081.   var NERO_PHASE_DRM_CHECK_FAILURE            = 169;
  1082.   var NERO_PHASE_START_WRITE_DATAFILES        = 171;    
  1083.   var NERO_PHASE_DONE_WRITE_DATAFILES        = 172;  
  1084.   var NERO_PHASE_FAIL_WRITE_DATAFILES        = 173;    
  1085.   var NERO_PHASE_WARN_WRITE_DATAFILES        = 174;    
  1086.   var NERO_PHASE_START_BAO_FINALIZE            = 175;    
  1087.   var NERO_PHASE_FAIL_BAO_FINALIZE            = 176;    
  1088.   var NERO_PHASE_DONE_BAO_FINALIZE            = 177;    
  1089.   var NERO_PHASE_FAIL_BAO_PREPARE            = 178;    
  1090.   var NERO_PHASE_FAIL_BAO_WRITEFILE            = 179;    
  1091.   var NERO_PHASE_BURN_LAYER_1                = 180;    
  1092.   var NERO_PHASE_BURN_LAYER_2                = 181;    
  1093.  
  1094.  
  1095.   var comServerState;
  1096.   var comServerBusy;
  1097.   var lastMessageStat = NERO_PHASE_IDLE;
  1098.  
  1099.  
  1100.   /// this method is executed periodically to query the status from
  1101.   /// the com server
  1102.   function COMServerTimer()
  1103.   {
  1104.     // if no server -skip this part
  1105.     if (SafeCOMServer() == null)
  1106.         return;
  1107.         
  1108.     // Notify the server that the gadget is still running
  1109.     // (under some conditions Windows doesn't call onUnload on the gadget document
  1110.     // and the server remains in memory. Now the sevrer closes if the callback is not
  1111.     // called for some time, and we need to notify the server so it doesn't close)
  1112.     SafeCOMServer().KeepAlive(120000);
  1113.  
  1114.     var serverState = SafeCOMServer().GetBurningState();
  1115.     if( serverState != comServerState )
  1116.     {
  1117.         comServerState = serverState;
  1118.         COMServerDebugText( "Burning State: "+serverState );
  1119.     }
  1120.  
  1121.     var serverBusy = ( serverState > 0 );
  1122.     if( serverBusy != comServerBusy )
  1123.     {
  1124.         comServerBusy = serverBusy;
  1125.         if( !serverBusy )
  1126.         {
  1127.             msg = SafeCOMServer().GetErrorMessage();
  1128.             COMServerDebugText( "Error message: "+msg );
  1129.         }
  1130.     }
  1131.  
  1132.     var stat = SafeCOMServer().GetWaitCDPopupStatus();
  1133.     if ( ((stat & 3) == 0 && bDialogWaitForCD) || ((stat & 4) !=0))
  1134.     {
  1135.        if (bModalDialog)
  1136.        {
  1137.          bModalDialog = false;
  1138.          ShowMessages();
  1139.        }
  1140.  
  1141.        bDialogWaitForCD = false;    
  1142.     } else
  1143.     if ((stat & 3) !=0)
  1144.     {
  1145.       DialogHeading = RemoveLanguageTags(L_WaitCD);
  1146.       DialogMessage = SafeCOMServer().GetWaitCDPopupText();
  1147.       bDialogWaitForCD = true;
  1148.       if (!bModalDialog)
  1149.         AddMessage(DialogHeading + ' ' + RemoveLanguageTags(L_Dialog));
  1150.       ShowDialog();
  1151.       return;
  1152.     };
  1153.     
  1154.     if( !bModalDialog && SafeCOMServer().IsPopupWaiting() )
  1155.     {
  1156.       DialogHeading = SafeCOMServer().GetPopupTitle();
  1157.       DialogMessage = SafeCOMServer().GetPopupText();
  1158.       AddMessage(DialogHeading);
  1159.       bDialogPopup = true;
  1160.       ShowDialog();
  1161.       return;
  1162.     }
  1163.  
  1164.     iProgressPercent = SafeCOMServer().GetProgressInPercent();
  1165.     CheckCurrentStatusText(SafeCOMServer().GetBurningStateText());
  1166.     
  1167.     stat = serverState;
  1168.     if ((stat == NERO_PHASE_START_CACHE) ||
  1169.         (stat == NERO_PHASE_BURN_PROCESS_STARTED) ||
  1170.         (stat == NERO_PHASE_VERIFY_COMPILATION) ||
  1171.         (stat == NERO_PHASE_BUILD_IMAGE)
  1172.        )
  1173.     {
  1174.       bReading = true;
  1175.       bBurning = false;
  1176.       if ((lastMessageStat!=stat) && ( stat == NERO_PHASE_BURN_PROCESS_STARTED))
  1177.             AddMessage(RemoveLanguageTags(L_BurningStarted));
  1178.     } else
  1179.     if (( stat == NERO_PHASE_START_SIMULATE) ||
  1180.         ( stat == NERO_PHASE_START_WRITE) ||
  1181.         ( stat == NERO_PHASE_START_SIMULATE_NOSPD) ||
  1182.         ( stat == NERO_PHASE_START_WRITE_NOSPD) ||
  1183.         ( stat == NERO_PHASE_START_FORMATTING) ||
  1184.         ( stat == NERO_PHASE_DVDVIDEO_REALLOC_STARTED) ||
  1185.         ( stat == NERO_PHASE_START_WRITE_DATAFILES) ||
  1186.         ( stat == NERO_PHASE_START_BAO_FINALIZE)
  1187.        )
  1188.     {
  1189.       bReading = false;
  1190.       bBurning = true;
  1191.       // show the finalizing animation
  1192.       if (stat == NERO_PHASE_START_BAO_FINALIZE)
  1193.         iProgressPercent = 100;
  1194.     } else
  1195.     if (( stat == NERO_PHASE_PREPARE_ITEMS) ||
  1196.         ( stat == NERO_PHASE_PREPARE_CD) ||
  1197.         ( stat == NERO_PHASE_IDLE) ||
  1198.         ( stat == NERO_PHASE_BURNING_COMPLETE) ||
  1199.         ( stat == NERO_PHASE_ABORT) ||
  1200.         ( stat == NERO_PHASE_ERROR)
  1201.        )
  1202.     {
  1203.       iProgressPercent = 0;
  1204.       bReading = false;
  1205.       bBurning = false;
  1206.       
  1207.       if (lastMessageStat!=stat)
  1208.         if ( stat == NERO_PHASE_BURNING_COMPLETE)
  1209.             AddMessage(RemoveLanguageTags(L_BurningComplete));
  1210.         else
  1211.         if ( stat == NERO_PHASE_ABORT)
  1212.             AddMessage(RemoveLanguageTags(L_BurningAborted));
  1213.         else
  1214.         if ( stat == NERO_PHASE_ERROR)
  1215.             AddMessage(RemoveLanguageTags(L_BurningError));
  1216.         else
  1217.         if ( stat == NERO_PHASE_BURN_PROCESS_STARTED)
  1218.             AddMessage(RemoveLanguageTags(L_BurningStarted));
  1219.     };
  1220.     lastMessageStat = stat;
  1221.   };
  1222.  
  1223.  
  1224.   /// this is called when the copy button is clicked
  1225.   function StartCopy()
  1226.   {
  1227.     bErrorTextPresent = false;
  1228.     if( SafeCOMServer() != null )
  1229.     {
  1230.         ClearMessages();
  1231.         SafeCOMServer().StartBurn( true );
  1232.     }
  1233.   };
  1234.  
  1235.   /// this is called when the cancel button is clicked
  1236.   function CancelCopy()
  1237.   {
  1238.     if( SafeCOMServer() != null )
  1239.     {
  1240.         AddMessage(RemoveLanguageTags(L_UserAborted));
  1241.         SafeCOMServer().StartBurn( false );
  1242.     }
  1243.   };
  1244.  
  1245.   /// increment the number of copies
  1246.   function IncCopies()
  1247.   {
  1248.     if (SafeCOMServer() == null)
  1249.       return;
  1250.     SafeCOMServer().SetNumberOfCopies( SafeCOMServer().GetNumberOfCopies() +1 );
  1251.   };
  1252.  
  1253.   /// decrement the number of copies
  1254.   function DecCopies()
  1255.   {
  1256.     if (SafeCOMServer() == null)
  1257.       return;
  1258.     SafeCOMServer().SetNumberOfCopies( SafeCOMServer().GetNumberOfCopies() -1 );
  1259.   };
  1260.  
  1261.   /// returns the number of copies
  1262.   function GetCopies()
  1263.   {
  1264.     if (SafeCOMServer() == null)
  1265.       return 0;
  1266.     return SafeCOMServer().GetNumberOfCopies()-((SafeCOMServer().GetNumberOfActualCopy()<=0)?0:(SafeCOMServer().GetNumberOfActualCopy()-1));
  1267.   };
  1268.   
  1269.   function OnOk()
  1270.   {
  1271.     ShowDetails();
  1272.  
  1273.     if( bDialogWaitForCD )
  1274.       SafeCOMServer().SetWaitCDPopupResult(WAITCD_POPUP_BUTTON_OK|WAITCD_POPUP_BUTTON_LOAD|WAITCD_POPUP_BUTTON_ERASE);
  1275.  
  1276.     if( bDialogPopup )
  1277.       SafeCOMServer().SetPopupResult( IDOK );
  1278.   };
  1279.   
  1280.   function OnCancel()
  1281.   {
  1282.     ShowDetails();
  1283.     AddMessage(RemoveLanguageTags(L_UserAborted));
  1284.      
  1285.     if( bDialogWaitForCD )
  1286.       SafeCOMServer().SetWaitCDPopupResult( WAITCD_POPUP_BUTTON_STOP );
  1287.  
  1288.     if( bDialogPopup )
  1289.       SafeCOMServer().SetPopupResult( IDCANCEL );
  1290.   };
  1291.  
  1292.   
  1293.   function COMServerInitialize()
  1294.   {
  1295.     if ( COMServer == null)
  1296.     {
  1297.       try {
  1298.        COMServer = new ActiveXObject( "NeroGadgetCMServer.NeroGadgetCM" ); // Nero Gadget COM Server
  1299.       } catch(e)
  1300.       {
  1301.         // ignore errors
  1302.       };
  1303.     }
  1304.  
  1305.     // if there is still no COM Server - stop       
  1306.     if( COMServer == null )
  1307.         return;
  1308.  
  1309.     //comServer.BurnImageFile("D:\\TestDisk.iso");
  1310.  
  1311.     var i = SafeCOMServer().GetSelectedReaderDrive();
  1312.     var msg = "Reader drive: ";
  1313.     if( i < 0 )
  1314.         msg += "not found.";
  1315.     else
  1316.         msg += SafeCOMServer().GetReaderDriveName( i );
  1317.     COMServerDebugText( msg );
  1318.  
  1319.     i = SafeCOMServer().GetSelectedBurnDrive();
  1320.     var msg = "Burner drive: ";
  1321.     if( i < 0 )
  1322.         msg += "not found.";
  1323.     else
  1324.         msg += SafeCOMServer().GetBurnDriveName( i );
  1325.     COMServerDebugText( msg );
  1326.  
  1327.     COMServerTimer();
  1328.   }
  1329.  
  1330.  
  1331.   /// prints a debug text in the output window of a native debugger
  1332.   /// @text: the text to show
  1333.   function COMServerDebugText( text )
  1334.   {
  1335.     if( SafeCOMServer() != null )
  1336.     {
  1337.         SafeCOMServer().OutputDebugText( text );
  1338.     }  
  1339.   }
  1340.  
  1341.   //////////////////////////////// init ////////////////////////////////////////
  1342.   
  1343.   /// this is called when user rolls the mouse wheel.
  1344.   function OnWheel(event) {
  1345.      if (!event) event = window.event;
  1346.      var delta = 0;
  1347.      if (event.wheelDelta)
  1348.           delta = event.wheelDelta;
  1349.      if (delta) {
  1350.           if (delta<0)
  1351.                DecCopiesButtonClicked();
  1352.           else
  1353.                IncCopiesButtonClicked();
  1354.      }
  1355.   }
  1356.   
  1357.   
  1358.   /// this is called to re-read the settings
  1359.   function SettingsChanged()
  1360.   {
  1361.     SafeCOMServer().LoadPersistency(PersistentFileName);
  1362.     UpdateDisplay();
  1363.   }
  1364.   
  1365.   /// this is called when the user closed the settings
  1366.   function SettingsClosed(event)
  1367.   {
  1368.     if (event.closeAction == event.Action.commit)
  1369.        SettingsChanged();
  1370.   }
  1371.   
  1372.   /// this function is called when user drops some items into the gadget
  1373.   function OnItemsDropped()
  1374.   {
  1375.     var item = System.Shell.itemFromFileDrop(event.dataTransfer, 0);
  1376.     var item2 = System.Shell.itemFromFileDrop(event.dataTransfer, 1);
  1377.     
  1378.     if (item == null)
  1379.     {
  1380.       AddMessage(RemoveLanguageTags(L_DropError));
  1381.       ShowDetails();
  1382.     } else
  1383.     if (item2 != null)
  1384.     {
  1385.       AddMessage(RemoveLanguageTags(L_DropErrorMultipleFiles));
  1386.       showDetails();
  1387.     } else
  1388.     if (item.isLink)
  1389.     {
  1390.       AddMessage(RemoveLanguageTags(L_DropErrorLink));
  1391.       showDetails();    
  1392.     } else
  1393.     if (item.isFolder)
  1394.     {
  1395.       AddMessage(RemoveLanguageTags(L_DropErrorFolder));
  1396.       showDetails();
  1397.     } else
  1398.     if (SafeCOMServer().GetBurningState()>=NERO_PHASE_BURN_PROCESS_STARTED)
  1399.     {
  1400.       AddMessage(RemoveLanguageTags(L_DropErrorAlreadyBurning));
  1401.       showDetails();
  1402.     } else
  1403.     {
  1404.       ClearMessages();
  1405.       AddMessage(RemoveLanguageTags(L_DropBurningStarted));
  1406.       SafeCOMServer().BurnImageFile(item.path);
  1407.     }
  1408.   }
  1409.   
  1410.   function OnDragEnter()
  1411.   {
  1412.      event.returnValue = false;
  1413.   }
  1414.   
  1415.   function OnDragOver()
  1416.   {
  1417.     event.returnValue = false;
  1418.   }
  1419.  
  1420.   function reset()
  1421.   {
  1422.      HideDetails();
  1423.      UpdateStatus();
  1424.      DisplayImg.onmousewheel = LSDigitImg.onmousewheel= MSDigitImg.onmousewheel=
  1425.        MainButtonImg.onmousewheel=
  1426.        IncCopiesImg.onmousewheel= DecCopiesImg.onmousewheel = OnWheel;
  1427.        
  1428.      var i;
  1429.      for (i=0;i<document.all.length;++i)
  1430.      {
  1431.         if (document.all[i].onmouseover == null)
  1432.           document.all[i].onmouseover = AutoSlideOut;
  1433.         if (document.all[i].onclick == null)
  1434.           document.all[i].onclick = ShowDetails;
  1435.         if (document.all[i].onmouseout == null)
  1436.           document.all[i].onmouseout = AutoSlideIn;
  1437.         if (document.all[i].ondragenter == null)
  1438.           document.all[i].ondragenter = OnDragEnter;
  1439.         if (document.all[i].ondragover == null)
  1440.           document.all[i].ondragover = OnDragOver;        
  1441.      }
  1442.      
  1443.      setTimeout("DelaySlideOut()",1);
  1444.      setTimeout("HideDetails()",5000);
  1445.      
  1446.     // init flyout before setting up com server
  1447.     // so we can dispplay messages
  1448.     System.Gadget.Flyout.file = "flyout.html";
  1449.     System.Gadget.Flyout.show = true;
  1450.  
  1451.     COMServerInitialize();
  1452.     if( COMServer == null ) // COM server creation error
  1453.     {
  1454.       AddMessage("COM Server not found.");
  1455.       AddMessage("Critical Error");
  1456.       return;
  1457.     };
  1458.     
  1459.     // show versions only when server initialized
  1460.     System.Gadget.Flyout.onShow = OnShowVersion;
  1461.  
  1462.     // allow settings only if com server is present
  1463.     // so init them after setup of the com server
  1464.     System.Gadget.settingsUI = "settings.html";
  1465.     System.Gadget.onSettingsClosed = SettingsClosed;
  1466.     
  1467.     PersistentFileName = System.Gadget.Settings.read("PersistentFileName");
  1468.     if (PersistentFileName == "")
  1469.     {
  1470.         PersistentFileName = SafeCOMServer().GeneratePersistencyFileName();
  1471.         System.Gadget.Settings.write("PersistentFileName", PersistentFileName);
  1472.         SafeCOMServer().SavePersistency(PersistentFileName);
  1473.     }
  1474.     else
  1475.         SafeCOMServer().LoadPersistency(PersistentFileName);
  1476.  
  1477.     UpdateStatus();
  1478.   };
  1479.   
  1480.